package com.threefish.common.config;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
import org.nutz.dao.Dao;
import org.nutz.dao.impl.NutDao;
import org.nutz.integration.spring.SpringDaoRunner;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * @author 黄川 huchuc@vip.qq.com
 * @date: 2018/9/6
 */
@Component
public class NutDaosConfig {

    @Bean
    @ConfigurationProperties("spring.datasource.druid")
    public DruidDataSource dataSourceOne() {
        return DruidDataSourceBuilder.create().build();
    }

    @Bean
    public SpringDaoRunner springDaoRunner() {
        return new SpringDaoRunner();
    }

    @Bean
    public Dao dao(DruidDataSource dataSource, SpringDaoRunner springDaoRunner) {
        NutDao dao = new NutDao(dataSource);
        dao.setRunner(springDaoRunner);
        return dao;
    }
}
